package com.e3.basdoc.region.client;

import java.util.List;

import com.e3.basdoc.region.model.RegionModel;
import com.e3.template.tgf.MyTGFUI;
import com.e3.template.tgf.TGFEditorDialog;
import com.e3.template.tgf.TGFGridPanel;
import com.e3.template.tgf.TGFQueryDialog;
import com.e3.template.tgf.TGFSimpleFormPanel;
import com.e3.template.tgf.TGFStateMachine;
import com.e3.template.tgf.TGFTreePanelAsync;
import com.e3.web.core.client.GXTHelper;
import com.e3.web.widget.client.BaseAction;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class RegionUI extends MyTGFUI<RegionModel> {
	
	private RegionRPCServiceAsync service = RegionRPCService.Util.getInstance();

	@Override
	protected TGFSimpleFormPanel<RegionModel> createFormPanel() {
		return new RegionFormPanel();
	}

	@Override
	protected TGFGridPanel<RegionModel> createGridPanel() {
		return new RegionGridPanel();
	}

	@Override
	protected TGFTreePanelAsync<RegionModel> createTreePanel() {
		return new RegionTreePanel();
	}

	@Override
	protected TGFQueryDialog<RegionModel> createQueryDialog() {
		return new RegionQueryDialog();
	}

	@Override
	protected TGFEditorDialog<RegionModel> createEditorDialog() {
		return new RegionEditorDialog();
	}

	@Override
	protected void executeDeleteService(final List<RegionModel> models,AsyncCallback<Void> callback) {
		service.deleteRegions(models, callback);
	}

	@Override
	protected String getCurrentLocalName() {
		return RegionMessages.INSTANCE.local_name();
	}

	@Override
	protected RegionModel createModelInstance() {
		return new RegionModel();
	}
	
	@Override
	protected String getDeletedDetailInfo(List<RegionModel> models) {
		String msgs = super.getDeletedDetailInfo(models);
		return msgs+";"+RegionMessages.INSTANCE.msg_delete_confirm_notice();
	}
	
	@Override
	protected BaseAction[] getTreeGridContextMenuActions() {
		if(GXTHelper.isSuperAdmin()){
			return super.getTreeGridContextMenuActions();	
		}
		return new BaseAction[]{TGFStateMachine.NEW_CHILD_ACTION,TGFStateMachine.NEW_ACTION,TGFStateMachine.MODIFY_ACTION};
	}

	@Override
	protected BaseAction[] getToolButtonActions() {
		if(GXTHelper.isSuperAdmin()){
			return super.getToolButtonActions();
		}
		return new BaseAction[]{TGFStateMachine.QUERY_ACTION,TGFStateMachine.NEW_ACTION,TGFStateMachine.MODIFY_ACTION};
	}
}
